#!/usr/bin/env python

import sys
import os
import csv

def calc_price(file_name):
    with open(file_name, newline='', encoding='UTF-16LE') as csvfile:
        reader = csv.DictReader(csvfile, delimiter='\t')
        sum = 0
        for row in reader:
            q, p = int(row['Quantity']), float(row['Price'])
            sum += q * p
        return sum

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print('Usage:\n{} <BOM folder path>'.format(sys.argv[0]))
        sys.exit(0)
    folder = sys.argv[1]
    names = os.listdir(folder)
    total_price = 0
    for name in names:
        ext = os.path.splitext(name)[1]
        if ext != '.csv':
            continue
        file_path = os.path.join(folder, name)
        price = calc_price(file_path)
        total_price += price
        print("{}: {:.2f}".format(name, price))
    print("合计：{:.2f}".format(total_price))